﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Things.IDAL;
using Things.DBUtility;
using System.Collections.Generic;//Please add references
namespace Things.SQLServerDAL
{
	/// <summary>
	/// 数据访问类:GoodsOrders
	/// </summary>
	public partial class GoodsOrders:IGoodsOrders
	{
        protected string sqlIsUserHasBuyedGoods = @"select COUNT(1) 
                                                    from Things_GoodsOrders as T1
	                                                    join Things_GoodsOrderPriceR as T2 on T1.GoodsOrdersID=t2.GoodsOrderID
                                                    where T1.BuyerAccount='{0}' and T2.GoodsPriceID='{1}' and T1.[Status]='{2}'";

        protected string sqlSelectGoodsOrdersFilter = @"select T1.GoodsOrdersID, t1.BuyerAccount,t1.TotalPrice, t1.BuyDate, t1.BuyerAddress, t1.Status, T1.GoodsOrderNumber, gor.GoodsPriceID
                                                    from Things_GoodsOrders as T1
	                                                    join Things_GoodsOrderPriceR as gor on t1.GoodsOrdersID=gor.GoodsOrderID
                                                    where t1.BuyerAccount=@BuyerAccount and t1.BuyDate>@BuyDate and t1.GoodsOrderNumber like @GoodsOrderNumber
                                                    order by t1.BuyDate desc";

        protected string sqlSelectGoodsOrders = @"select distinct T1.GoodsOrdersID, t1.BuyerAccount,t1.TotalPrice, t1.BuyDate, t1.BuyerAddress, t1.Status, T1.GoodsOrderNumber
                                                    from Things_GoodsOrders as T1
	                                                    join Things_GoodsOrderPriceR as gor on t1.GoodsOrdersID=gor.GoodsOrderID
                                                    where t1.BuyerAccount='{0}' 
                                                    order by t1.BuyDate desc";

        protected string sqlSelectGoodsListByGoodsOrderID = @"select distinct gor.GoodsPriceID, T1.GoodsOrderNumber, gp.ShangPinBianHao,  gp.GoodsStandPrice, gor.Price, gor.Count, g.GoodsName, gp.GoodsStandPrice-gor.Price as SavePrice, gc.GoodsCategoryName
                                                                from Things_GoodsOrders as T1
                                                                    join Things_GoodsOrderPriceR as gor on t1.GoodsOrdersID=gor.GoodsOrderID
                                                                    join Things_GoodsPrice as gp on gor.GoodsPriceID=gp.ID
                                                                    join Things_Goods as g on gp.GoodsID=g.GoodsID
                                                                    join Things_GoodsCategory as gc on g.GoodsCategoryID=gc.ID
                                                                where T1.GoodsOrdersID='{0}'";

        protected string sqlSelectXiaoShouJiLu = @"select BuyerAccount, BuyDate, t1.Status, t2.[Count],Price, t2.GoodsPriceID, t2.GoodsOrderID
                                                    from Things_GoodsOrders as T1 
	                                                    join Things_GoodsOrderPriceR as T2 on T1.GoodsOrdersID=t2.GoodsOrderID
                                                    where t2.GoodsPriceID=@GoodsPriceID and t1.Status=@Status
                                                    order by BuyDate desc";

        protected string sqlSelectTopSaledGoods = @"select top {0} ROW_NUMBER() OVER (Order by COUNT(t2.Count) desc) AS RowNumber, T2.GoodsPriceID, COUNT(t2.Count) as c1 , t4.GoodsName
                                                    from Things_GoodsOrders as T1 
                                                        join Things_GoodsOrderPriceR as T2 on T1.GoodsOrdersID=t2.GoodsOrderID
                                                        join Things_GoodsPrice as T3 on T2.GoodsPriceID=T3.ID
                                                        join Things_Goods as t4 on t3.GoodsID=t4.GoodsID
                                                    group by T2.GoodsPriceID, t4.GoodsName";



		public GoodsOrders()
		{}
		#region  Method

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(Guid GoodsOrdersID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from Things_GoodsOrders");
			strSql.Append(" where GoodsOrdersID=@GoodsOrdersID ");
			SqlParameter[] parameters = {
					new SqlParameter("@GoodsOrdersID", SqlDbType.UniqueIdentifier,16)			};
			parameters[0].Value = GoodsOrdersID;

			return DbHelperSQL.Exists(strSql.ToString(),parameters);
		}

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(string userAccount, Guid GoodsPriceID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(@"select COUNT(1) 
                            from Things_GoodsOrders as T1
	                            join Things_GoodsOrderPriceR as T2 on T1.GoodsOrdersID=t2.GoodsOrderID
                            where T1.BuyerAccount=@BuyerAccount and T2.GoodsPriceID=@GoodsPriceID and T1.[Status]='已签收'");
  
            SqlParameter[] parameters = {
                    new SqlParameter("@BuyerAccount", SqlDbType.NVarChar,20),
					new SqlParameter("@GoodsPriceID", SqlDbType.UniqueIdentifier,16)                 };
            parameters[0].Value = userAccount;
            parameters[1].Value = GoodsPriceID;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }

        public int GetAllSuccessfulOrder(string userAccount, Guid GoodsPriceID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(@"select COUNT(1) 
                            from Things_GoodsOrders as T1
	                            join Things_GoodsOrderPriceR as T2 on T1.GoodsOrdersID=t2.GoodsOrderID
                            where T1.BuyerAccount=@BuyerAccount and T2.GoodsPriceID=@GoodsPriceID and T1.[Status]='已签收'");

            SqlParameter[] parameters = {
                    new SqlParameter("@BuyerAccount", SqlDbType.NVarChar,20),
					new SqlParameter("@GoodsPriceID", SqlDbType.UniqueIdentifier,16)                 };
            parameters[0].Value = userAccount;
            parameters[1].Value = GoodsPriceID;

            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            int result = 0;
            if (ds != null && ds.Tables.Count > 0)
            {
                result = ds.Tables[0].Rows.Count;
            }
            return result;
        }

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        //public bool Exists(string userAccount, Guid GoodsPriceID, string status)
        //{
        //    StringBuilder strSql = new StringBuilder();
        //    strSql.Append("select count(1) from Things_GoodsOrders");
        //    strSql.Append(" where GoodsOrdersID=@GoodsOrdersID ");
        //    SqlParameter[] parameters = {
        //            new SqlParameter("@BuyerAccount", SqlDbType.NVarChar,20),
        //            new SqlParameter("@GoodsOrdersID", SqlDbType.UniqueIdentifier,16),
        //            new SqlParameter("@Status", SqlDbType.NVarChar,50)                    };
        //    parameters[0].Value = userAccount;
        //    parameters[1].Value = GoodsPriceID;
        //    parameters[2].Value = status;

        //    return DbHelperSQL.Exists(strSql.ToString(), parameters);
        //}

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(Things.Model.GoodsOrders model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into Things_GoodsOrders(");
            strSql.Append("GoodsOrdersID,BuyerAccount,BuyerAddress,TotalPrice,BuyDate,SendDate,CancelDate,Status,IsCompleted,ModifiedDate,FaPiaoXinXi,BuyerComments,KuaiDiDanHao,PeiSongXinXi, KuaiDiGongSi)");
			strSql.Append(" values (");
            strSql.Append("@GoodsOrdersID,@BuyerAccount,@BuyerAddress,@TotalPrice,@BuyDate,@SendDate,@CancelDate,@Status,@IsCompleted,@ModifiedDate,@FaPiaoXinXi,@BuyerComments,@KuaiDiDanHao,@PeiSongXinXi, @KuaiDiGongSi)");
			SqlParameter[] parameters = {
					new SqlParameter("@GoodsOrdersID", SqlDbType.UniqueIdentifier,16),
					new SqlParameter("@BuyerAccount", SqlDbType.NVarChar,20),
					new SqlParameter("@BuyerAddress", SqlDbType.NVarChar,200),
					new SqlParameter("@TotalPrice", SqlDbType.Float,8),
					new SqlParameter("@BuyDate", SqlDbType.DateTime),
					new SqlParameter("@SendDate", SqlDbType.DateTime),
					new SqlParameter("@CancelDate", SqlDbType.DateTime),
					new SqlParameter("@Status", SqlDbType.NVarChar,50),
					new SqlParameter("@IsCompleted", SqlDbType.Bit,1),
					new SqlParameter("@ModifiedDate", SqlDbType.DateTime),
					new SqlParameter("@FaPiaoXinXi", SqlDbType.NVarChar,100),
					new SqlParameter("@BuyerComments", SqlDbType.NVarChar,500),
					new SqlParameter("@KuaiDiDanHao", SqlDbType.NVarChar,100),
					new SqlParameter("@PeiSongXinXi", SqlDbType.NVarChar,500),
					new SqlParameter("@KuaiDiGongSi", SqlDbType.NVarChar,50)};
            parameters[0].Value = model.GoodsOrdersID;
			parameters[1].Value = model.BuyerAccount;
			parameters[2].Value = model.BuyerAddress;
			parameters[3].Value = model.TotalPrice;
			parameters[4].Value = model.BuyDate;
			parameters[5].Value = model.SendDate;
			parameters[6].Value = model.CancelDate;
			parameters[7].Value = model.Status;
			parameters[8].Value = model.IsCompleted;
            parameters[9].Value = model.ModifiedDate;
            parameters[10].Value = model.FaPiaoXinXi;
            parameters[11].Value = model.BuyerComments;
            parameters[12].Value = model.KuaiDiDanHao;
            parameters[13].Value = model.PeiSongXinXi;
            parameters[14].Value = model.KuaiDiGongSi;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(Things.Model.GoodsOrders model)
		{
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update Things_GoodsOrders set ");
            strSql.Append("GoodsOrdersID=@GoodsOrdersID,");
            strSql.Append("BuyerAccount=@BuyerAccount,");
            strSql.Append("BuyerAddress=@BuyerAddress,");
            strSql.Append("TotalPrice=@TotalPrice,");
            strSql.Append("BuyDate=@BuyDate,");
            strSql.Append("SendDate=@SendDate,");
            strSql.Append("CancelDate=@CancelDate,");
            strSql.Append("Status=@Status,");
            strSql.Append("IsCompleted=@IsCompleted,");
            strSql.Append("ModifiedDate=@ModifiedDate,");
            strSql.Append("FaPiaoXinXi=@FaPiaoXinXi,");
            strSql.Append("BuyerComments=@BuyerComments,");
            strSql.Append("KuaiDiDanHao=@KuaiDiDanHao,");
            strSql.Append("PeiSongXinXi=@PeiSongXinXi, ");
            strSql.Append("KuaiDiGongSi=@KuaiDiGongSi");
            strSql.Append(" where GoodsOrdersID=@GoodsOrdersID ");
            SqlParameter[] parameters = {
					new SqlParameter("@GoodsOrdersID", SqlDbType.UniqueIdentifier,16),
					new SqlParameter("@BuyerAccount", SqlDbType.NVarChar,20),
					new SqlParameter("@BuyerAddress", SqlDbType.NVarChar,200),
					new SqlParameter("@TotalPrice", SqlDbType.Float,8),
					new SqlParameter("@BuyDate", SqlDbType.DateTime),
					new SqlParameter("@SendDate", SqlDbType.DateTime),
					new SqlParameter("@CancelDate", SqlDbType.DateTime),
					new SqlParameter("@Status", SqlDbType.NVarChar,50),
					new SqlParameter("@IsCompleted", SqlDbType.Bit,1),
					new SqlParameter("@ModifiedDate", SqlDbType.DateTime),
					new SqlParameter("@FaPiaoXinXi", SqlDbType.NVarChar,100),
					new SqlParameter("@BuyerComments", SqlDbType.NVarChar,500),
					new SqlParameter("@KuaiDiDanHao", SqlDbType.NVarChar,100),
					new SqlParameter("@PeiSongXinXi", SqlDbType.NVarChar,500),
					new SqlParameter("@KuaiDiGongSi", SqlDbType.NVarChar,50)};
            parameters[0].Value = model.GoodsOrdersID;
            parameters[1].Value = model.BuyerAccount;
            parameters[2].Value = model.BuyerAddress;
            parameters[3].Value = model.TotalPrice;
            parameters[4].Value = model.BuyDate;
            parameters[5].Value = model.SendDate;
            parameters[6].Value = model.CancelDate;
            parameters[7].Value = model.Status;
            parameters[8].Value = model.IsCompleted;
            parameters[9].Value = model.ModifiedDate;
            parameters[10].Value = model.FaPiaoXinXi;
            parameters[11].Value = model.BuyerComments;
            parameters[12].Value = model.KuaiDiDanHao;
            parameters[13].Value = model.PeiSongXinXi;
            parameters[14].Value = model.KuaiDiGongSi;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(Guid GoodsOrdersID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from Things_GoodsOrders ");
			strSql.Append(" where GoodsOrdersID=@GoodsOrdersID ");
			SqlParameter[] parameters = {
					new SqlParameter("@GoodsOrdersID", SqlDbType.UniqueIdentifier,16)			};
			parameters[0].Value = GoodsOrdersID;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string GoodsOrdersIDlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from Things_GoodsOrders ");
			strSql.Append(" where GoodsOrdersID in ("+GoodsOrdersIDlist + ")  ");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Things.Model.GoodsOrders GetModel(Guid GoodsOrdersID)
		{

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 * from Things_GoodsOrders ");
            strSql.Append(" where GoodsOrdersID=@GoodsOrdersID ");
            SqlParameter[] parameters = {
					new SqlParameter("@GoodsOrdersID", SqlDbType.UniqueIdentifier,16)			};
            parameters[0].Value = GoodsOrdersID;

            Things.Model.GoodsOrders model = new Things.Model.GoodsOrders();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
		}

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Things.Model.GoodsOrders GetModel(int GoodsOrderNumber)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 * from Things_GoodsOrders ");
            strSql.Append(" where GoodsOrderNumber=@GoodsOrderNumber ");
            SqlParameter[] parameters = {
					new SqlParameter("@GoodsOrderNumber", SqlDbType.Int)			};
            parameters[0].Value = GoodsOrderNumber;

            Things.Model.GoodsOrders model = new Things.Model.GoodsOrders();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 得到对象实体列表
        /// </summary>
        public List<Things.Model.GoodsOrders> GetModels(string strWhere)
        {
            List<Things.Model.GoodsOrders> modelList = new List<Things.Model.GoodsOrders>();
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 * from Things_GoodsOrders ");
            if (string.IsNullOrEmpty(strWhere) == false)
            {
                strSql.AppendFormat(" where {0}", strWhere);
            }
            DataSet ds = DbHelperSQL.Query(strSql.ToString());

            DataRowCollection rows=ds.Tables[0].Rows;
            foreach (DataRow row in rows)
            {
                Things.Model.GoodsOrders model = DataRowToModel(row);
                if (model != null)
                {
                    modelList.Add(model);
                }
            }

            return modelList;
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Things.Model.GoodsOrders DataRowToModel(DataRow row)
        {
            Things.Model.GoodsOrders model = new Things.Model.GoodsOrders();
            if (row != null)
            {
                if (row["GoodsOrdersID"] != null && row["GoodsOrdersID"].ToString() != "")
                {
                    model.GoodsOrdersID = new Guid(row["GoodsOrdersID"].ToString());
                }
                if (row["BuyerAccount"] != null)
                {
                    model.BuyerAccount = row["BuyerAccount"].ToString();
                }
                if (row["BuyerAddress"] != null)
                {
                    model.BuyerAddress = row["BuyerAddress"].ToString();
                }
                if (row["TotalPrice"] != null && row["TotalPrice"].ToString() != "")
                {
                    model.TotalPrice = decimal.Parse(row["TotalPrice"].ToString());
                }
                if (row["BuyDate"] != null && row["BuyDate"].ToString() != "")
                {
                    model.BuyDate = DateTime.Parse(row["BuyDate"].ToString());
                }
                if (row["SendDate"] != null && row["SendDate"].ToString() != "")
                {
                    model.SendDate = DateTime.Parse(row["SendDate"].ToString());
                }
                if (row["CancelDate"] != null && row["CancelDate"].ToString() != "")
                {
                    model.CancelDate = DateTime.Parse(row["CancelDate"].ToString());
                }
                if (row["Status"] != null)
                {
                    model.Status = row["Status"].ToString();
                }
                if (row["IsCompleted"] != null && row["IsCompleted"].ToString() != "")
                {
                    if ((row["IsCompleted"].ToString() == "1") || (row["IsCompleted"].ToString().ToLower() == "true"))
                    {
                        model.IsCompleted = true;
                    }
                    else
                    {
                        model.IsCompleted = false;
                    }
                }
                if (row["ModifiedDate"] != null && row["ModifiedDate"].ToString() != "")
                {
                    model.ModifiedDate = DateTime.Parse(row["ModifiedDate"].ToString());
                }
                if (row["FaPiaoXinXi"] != null)
                {
                    model.FaPiaoXinXi = row["FaPiaoXinXi"].ToString();
                }
                if (row["GoodsOrderNumber"] != null && row["GoodsOrderNumber"].ToString() != "")
                {
                    model.GoodsOrderNumber = int.Parse(row["GoodsOrderNumber"].ToString());
                }
                if (row["BuyerComments"] != null)
                {
                    model.BuyerComments = row["BuyerComments"].ToString();
                }
                if (row["KuaiDiDanHao"] != null)
                {
                    model.KuaiDiDanHao = row["KuaiDiDanHao"].ToString();
                }
                if (row["PeiSongXinXi"] != null)
                {
                    model.PeiSongXinXi = row["PeiSongXinXi"].ToString();
                }
                if (row["KuaiDiGongSi"] != null)
                {
                    model.KuaiDiGongSi = row["KuaiDiGongSi"].ToString();
                }
            }
            return model;
        }

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select * ");
			strSql.Append(" FROM Things_GoodsOrders ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}


        /// <summary>
        /// 订单查询
        /// </summary>
        public DataSet GetList(string buyerAccount, DateTime filterDate, string keyword)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(sqlSelectGoodsOrdersFilter);

            SqlParameter[] parameters = {
                    new SqlParameter("@BuyerAccount", SqlDbType.NVarChar,20),
                    new SqlParameter("@BuyDate", SqlDbType.DateTime),
					new SqlParameter("@GoodsOrderNumber", SqlDbType.NVarChar, 10)                 };
            parameters[0].Value = buyerAccount;
            parameters[1].Value = filterDate;
            parameters[2].Value = "%" + keyword + "%";

            return DbHelperSQL.Query(strSql.ToString(), parameters);
        }

        /// <summary>
        /// 销售记录
        /// </summary>
        public DataSet GetList(Guid goodsPriceID, string status)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(sqlSelectXiaoShouJiLu);

            SqlParameter[] parameters = {
                    new SqlParameter("@GoodsPriceID", SqlDbType.UniqueIdentifier, 16),
					new SqlParameter("@Status", SqlDbType.NVarChar, 10)                 };
            parameters[0].Value = goodsPriceID;
            parameters[1].Value = status;

            return DbHelperSQL.Query(strSql.ToString(), parameters);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetListByBuyerAccount(string buyerAccount)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.AppendFormat(sqlSelectGoodsOrders, buyerAccount);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetGoodsListByGoodsOrderID(Guid goodsOrderID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.AppendFormat(sqlSelectGoodsListByGoodsOrderID, goodsOrderID);
            return DbHelperSQL.Query(strSql.ToString());
        }

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" * ");
			strSql.Append(" FROM Things_GoodsOrders ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM Things_GoodsOrders ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.GoodsOrdersID desc");
			}
			strSql.Append(")AS Row, T.*  from Things_GoodsOrders T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@tblName", SqlDbType.VarChar, 255),
					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
					new SqlParameter("@PageSize", SqlDbType.Int),
					new SqlParameter("@PageIndex", SqlDbType.Int),
					new SqlParameter("@IsReCount", SqlDbType.Bit),
					new SqlParameter("@OrderType", SqlDbType.Bit),
					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
					};
			parameters[0].Value = "Things_GoodsOrders";
			parameters[1].Value = "GoodsOrdersID";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/


        /// <summary>
        /// 获得销售排行榜
        /// </summary>
        public DataSet GetTopSaledList(int Top)
        {
            int topValue = Top > 0 ? Top : 10;
            StringBuilder strSql = new StringBuilder();
            strSql.AppendFormat(sqlSelectTopSaledGoods, topValue);
            
            return DbHelperSQL.Query(strSql.ToString());
        }

		#endregion  Method
	}
}

